/**
 * 
 */
package hw2.cs236369.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import hw2.cs236369.interfaces.IAuthor;
import hw2.cs236369.interfaces.IDBLP;
import hw2.cs236369.interfaces.IPaper;
import hw2.cs236369.parsing.Author;
import hw2.cs236369.parsing.DBLParser;
import hw2.cs236369.parsing.Paper;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import org.junit.BeforeClass;
import org.junit.Test;


/**
 * @author gil
 * 
 */
public class DBLParserTest {
	private static IDBLP	parser;

	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		parser = new DBLParser("dblp.xml", "^E.*");
	}

	/**
	 * Test method for {@link hw2.cs236369.parsing.DBLParser#getFilteredAuthors()}.
	 */
	@Test
	public void testGetFilteredAuthors() {
		Collection<IAuthor> expected = new ArrayList<IAuthor>(Arrays.asList(new Author("E. F. Codd")));
		Collection<IAuthor> c = parser.getFilteredAuthors();
		assertEquals(1, c.size());
		assertTrue(expected.containsAll(c));
		assertTrue(c.containsAll(expected));

	}

	/**
	 * Test method for {@link hw2.cs236369.parsing.DBLParser#getPapers(hw2.cs236369.interfaces.IAuthor)}.
	 */
	@Test
	public void testGetPapers() {
		Collection<IPaper> expected = new ArrayList<IPaper>(
				Arrays.asList(
						new Paper(1971, new ArrayList<IAuthor>(Arrays.asList(new Author(
								"E. F. Codd")))),
						new Paper(1974, new ArrayList<IAuthor>(
								Arrays.asList(new Author("E. F. Codd"), new Author("C. J. Date")))),
						new Paper(1971, new ArrayList<IAuthor>(Arrays.asList(new Author(
								"E. F. Codd")))),
						new Paper(1972, new ArrayList<IAuthor>(Arrays.asList(new Author(
								"E. F. Codd"))))));
		Collection<IPaper> c = parser.getPapers(new Author("E. F. Codd"));
		assertEquals(4, c.size());
		assertEquals(expected, c);
	}

}
